﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.LongER.Framework.Utils;
using Com.LongER.UI;
using Com.LongER.Business.ZHM009;
using Com.LongER.Framework.Utils.LogUtils;


public partial class ZHM009 : ABasePage
{
    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        //
        if (!this.Page.IsPostBack)
        {
            Label lblPageId = (Label)Master.FindControl("lblPageId");
            lblPageId.Text = "ZHM009";

            Label lblPageName = (Label)Master.FindControl("lblPageName");
            lblPageName.Text = "客户一览查询画面";

            //清空画面中的输入框
            #region
            proc清空_Init("0"); 

            #endregion
            //焦点位于用户ID输入框中
            this.txt客户CD.Focus();

        }
        //autocomplete
        this.txt客户.Text = this.hid客户.Value;
        this.txt所属区分.Text = this.hid所属区分.Value;
        this.txt合作性质.Text = this.hid合作性质.Value;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn主菜单_Click(object sender, EventArgs e)
    {
        Response.Redirect("/LongER/ZAH003.aspx");
    }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    protected void btn执行_Click(object sender, EventArgs e)
    {
        Dictionary<string, string> dic = new Dictionary<string, string>();
        dic.Add("KEHU_CD", this.txt客户CD.Text.ToString());
        dic.Add("SHO", this.txt所属区分CD.Text.ToString());
        dic.Add("HEZUO_XINGZHI", this.txt合作性质CD.Text.ToString());

        //
        if (this.hidPageNo.Value == string.Empty) this.hidPageNo.Value = "1";
        dic.Add("PAGE_NO", this.hidPageNo.Value);


        CZHM009 instance = new CZHM009();


        ZHM009DS.M_KEHUDataTable dt = instance.GetKehuList(dic);

        #region
        //总件数清空
        this.txt总件数.Text = string.Empty;
        //标题行以外全部移除
        for (int i = this.tblList.Rows.Count - 1; i >= 1; i--)
        {
            this.tblList.Rows.RemoveAt(i);
        }

        Label lblMsgCD = (Label)Master.FindControl("lblMsgCD");
        lblMsgCD.Text = "  ";

        Label lblMsg = (Label)Master.FindControl("lblMsg");
        lblMsg.Text = "  ";
        #endregion


        //查询结果不为空时
        if (dt.Count > 0)
        {
            this.txt总件数.Text = dt.Count.ToString();
        }
        //查询结果为空时
        else
        {
            String msg = MessageUtil.GetMessage("GTH002", "IGTH002001");

            lblMsgCD.Text = "IGTH002001";
            lblMsg.Text = msg;

            return;
        }

        int rowid = 0;
        //
        foreach (var dr in dt)
        {
            //创建新行
            TableRow row = new TableRow();
            if (rowid % 2 == 0) { row.CssClass = "odd"; } else { row.CssClass = "even"; }

            //选择
            TableCell cell = GetTableCell(width: 30, rowspan: 1);
            //
            RadioButton rb = new RadioButton();
            rb.ID = "rb" + rowid;
            rb.GroupName = "rad";
            if (rowid == 0) rb.Checked = true;

            cell.Controls.Add(rb);
            row.Cells.Add(cell);//插入单元格

            //客户CD
            cell = GetTableCell(width: 50);
            cell.Text = dr.KEHU_CD;
            row.Cells.Add(cell);

            //客户名
            cell = GetTableCell(width: 100);
            cell.Text = dr.KEHU_HANZI;
            row.Cells.Add(cell);

            //客户性质（所属区分）
            cell = GetTableCell(width: 60);
            cell.Text = dr.SHO;
            row.Cells.Add(cell);

            //合作性质
            cell = GetTableCell(width: 60);
            cell.Text = dr.HEZUO_XINGZHI;
            row.Cells.Add(cell);

            //联系人
            cell = GetTableCell(width: 50);
            cell.Text = dr.LIANXI_REN;
            row.Cells.Add(cell);

            //联系电话1
            cell = GetTableCell(width: 65);
            cell.Text = dr.TEL_NUM1;
            row.Cells.Add(cell);

            //联系电话2
            cell = GetTableCell(width: 65);
            cell.Text = dr.TEL_NUM2;
            row.Cells.Add(cell);

            //FAX1
            cell = GetTableCell(width: 70);
            cell.Text = dr.FAX1;
            row.Cells.Add(cell);

            //邮箱
            cell = GetTableCell(width: 100);
            cell.Text = dr.MAIL_ADDR;
            row.Cells.Add(cell);

            this.tblList.Rows.Add(row);


            rowid++;

        }

    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="width"></param>
    /// <param name="rowspan"></param>
    /// <returns></returns>
    private TableCell GetTableCell(int width = -1, int rowspan = 1, int colspan = 1)
    {
        //创建单元格对象
        TableCell cell = new TableCell();
        if (width != -1) cell.Width = width;
        if (rowspan > 1) cell.RowSpan = rowspan;
        if (colspan > 1) cell.ColumnSpan = colspan;
        return cell;
    }

    protected void proc清空_Init(string str处理区分)
    {
        Label lblMsgCD = (Label)Master.FindControl("lblMsgCD");
        Label lblMsg = (Label)Master.FindControl("lblMsg");
        lblMsgCD.Text = "";
        lblMsg.Text = "";

            //控件的Enabled进行控制
            #region
            this.txt客户CD.Enabled = true;

            this.txt所属区分CD.Enabled = true;
            this.txt合作性质CD.Enabled = true;
            #endregion

            //控件的Text进行清空
            #region
            this.txt客户CD.Text = string.Empty;
            this.txt客户.Text = string.Empty;
            //init
            if (str处理区分 == "0")
            {
                this.txt客户.Visible = false;
            }
            //查询
            else if (str处理区分 == "1")
            {
                this.txt客户.Visible =  true;
            }

            this.txt所属区分CD.Text = string.Empty;
            this.txt所属区分.Text = string.Empty;
            //init
            if (str处理区分 == "0")
            {
                this.txt所属区分.Visible = false;
            }
            //查询
            else if (str处理区分 == "1")
            {
                this.txt所属区分.Visible = true;
            }

            this.txt合作性质CD.Text = string.Empty;
            this.txt合作性质.Text = string.Empty;
            //init
            if (str处理区分 == "0")
            {
                this.txt合作性质.Visible = false;
            }
            //查询
            else if (str处理区分 == "1")
            {
                this.txt合作性质.Visible = true;
            }

            #endregion

            //总件数
            this.txt总件数.Text = string.Empty;

            //数据表清空
            for (int i = this.tblList.Rows.Count - 1; i >= 1; i--)
            {
                this.tblList.Rows.RemoveAt(i);
            }

    }

    protected void btn清除_Click(object sender, EventArgs e)
    {
        //初期化处理
        #region
        //查询时，各个控件的属性进行控制
        proc清空_Init("1");
        #endregion
    }


}